package bpd;

/**
 * The MoveToCenter class creates a battlefield, puts a robot in it, and tests the algorithm used
 * to move the robot to the center of the battlefield.
 * 
 * @author BJ Peter DeLaCruz
 * @version 1.0
 * 
 */
public class MoveToCenter {

  /** Width of the battlefield. */
  private double width;
  /** Height of the battlefield. */
  private double height;
  /** Robot's initial x-coordinate on the battlefield. */
  private double initialPositionX;
  /** Robot's initial y-coordinate on the battlefield. */
  private double initialPositionY;
  
  /**
   * Sets the width and height of the battlefield as well as the robot's initial position.
   * 
   * @param width Width of the battlefield
   * @param height Height of the battlefield
   * @param initialPositionX Initial x-coordinate of the robot on the battlefield
   * @param initialPositionY Initial y-coordinate of the robot on the battlefield
   */
  public MoveToCenter(double width, double height,
                      double initialPositionX, double initialPositionY) {
    
    this.width = width;
    this.height = height;
    this.initialPositionX = initialPositionX;
    this.initialPositionY = initialPositionY;
    
  }
  
  /**
   * Calculates the distance to the x-coordinate of the center of the battlefield given the robot's
   * initial x-coordinate.
   * 
   * @return Distance to the x-coordinate of the center of the battlefield
   */
  public double moveToCenterX() {
    
    // Get the x-coordinate for the center of the battlefield.
    double centerX = width / 2;
    
    // Move to the same x-coordinate as the center of the battlefield.
    return Math.abs(initialPositionX - centerX);

  }
  
  /**
   * Calculates the distance to the y-coordinate of the center of the battlefield given the robot's
   * initial y-coordinate.
   * 
   * @return Distance to the y-coordinate of the center of the battlefield
   */
  public double moveToCenterY() {
    
    // Get the y-coordinate for the center of the battlefield.
    double centerY = height / 2;
    
    // Move to the same y-coordinate as the center of the battlefield.
    return Math.abs(initialPositionY - centerY);

  }
  
  /**
   * Sets the initial x-coordinate of the robot.
   * 
   * @param positionX New x-coordinate of the robot
   */
  public void setPositionX(double positionX) {
    initialPositionX = positionX;
  }
  
  /**
   * Sets the initial y-coordinate of the robot.
   * 
   * @param positionY New y-coordinate of the robot
   */
  public void setPositionY(double positionY) {
    initialPositionY = positionY;
  }
  
  /**
   * Gets the initial x-coordinate of the robot.
   * 
   * @return X-coordinate of the robot
   */
  public double getPositionX() {
    return initialPositionX;
  }
  
  /**
   * Gets the initial y-coordinate of the robot.
   * 
   * @return Y-coordinate of the robot
   */
  public double getPositionY() {
    return initialPositionY;
  }

}
